﻿using Microsoft.Extensions.DependencyInjection;
using StartsEAS_API.BLL.Interfaces.IRegionalB;
using StartsEAS_API.DAL.RegionalD;
using StartsEAS_API.Model;
using StartsEAS_API.Model.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StartsEAS_API.BLL.RegionalB
{
    public class RegionalBLL: IRegionalBLL
    {
        private readonly StarsEASContext _context;

        public RegionalDAL _regionalDal;

        public RegionalBLL(IServiceScopeFactory context)
        {
            _context = context.CreateScope().ServiceProvider.GetRequiredService<StarsEASContext>();
            _regionalDal = new(_context);
        }
        
        public ResultUtils GetAllProvince()
        {
            IEnumerable<Province> provinces = _regionalDal.GetAllProvince();
            if (provinces == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = provinces };
        }

        public ResultUtils GetArea(int CityCode)
        {
            IEnumerable<Area> areas = _regionalDal.GetArea(CityCode);
            if (areas == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = areas };
        }

        public ResultUtils GetAreaByAreaCode(int AreaCode)
        {
            Area area = _regionalDal.GetAreaByAreaCode(AreaCode);
            if(area == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = area };
        }

        public ResultUtils GetAreaByAreaName(string AreaName)
        {
            Area area = _regionalDal.GetAreaByAreaName(AreaName);
            if (area == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = area };
        }

        public ResultUtils GetCity(int ProvinceCode)
        {
            IEnumerable<City> cities = _regionalDal.GetCity(ProvinceCode);
            if (cities == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = cities };
        }

        public ResultUtils GetCityByCityCode(int CityCode)
        {
            City city = _regionalDal.GetCityByCityCode(CityCode);
            if (city == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = city };
        }

        public ResultUtils GetCityByCityName(string CityName)
        {
            City city = _regionalDal.GetCityByCityName(CityName);
            if (city == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = city };
        }

        public ResultUtils GetProvincByProvinceCode(int ProvinceCode)
        {
            Province province = _regionalDal.GetProvincByProvinceCode(ProvinceCode);
            if (province == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = province };
        }

        public ResultUtils GetProvincByProvinceName(string ProvinceName)
        {
            Province province = _regionalDal.GetProvincByProvinceName(ProvinceName);
            if (province == null) return new ResultUtils() { code = 500, message = "数据为空" };
            return new ResultUtils() { code = 200, message = province };
        }
    }
}
